//
//  WaterViewController.m
//  bluetooth
//
//  Created by 周季阳 on 15/6/17.
//  Copyright (c) 2015年 switch. All rights reserved.
//

#import "WaterViewController.h"
#import "UIViewAdditions.h"
#import "BeginMakingViewController.h"
#import "AppDelegate.h"
#import "TwoHuoXingtaiViewController.h"
#import "OLImage.h"
#import "OLImageView.h"
#import "ShopViewController.h"
@interface WaterViewController ()<UIAlertViewDelegate>
{
    OLImageView *Aimv;
}
@end

@implementation WaterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(clicuo) name:@"clickend" object:nil];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(cdaoshui) name:@"cdaoshui" object:nil];
    // Do any additional setup after loading the view.
    [self createrView];

}
-(void)clicuo{
    [self.navigationController popToRootViewControllerAnimated:YES];

}
#pragma mark - initUI
-(void)createrView{
    UIImageView * imgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"制作完成.png"]];
    [imgView setFrame:[UIScreen mainScreen].bounds];
    [self.view addSubview:imgView];
    imgView.userInteractionEnabled = YES;
    
    UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    leftBtn.frame = CGRectMake(10, 40, 78, 26);
    [leftBtn setBackgroundImage:[UIImage imageNamed:@"15清洗-清洁导流槽_03(1)"] forState:UIControlStateNormal];
    [leftBtn addTarget:self action:@selector(clickLeftBtn) forControlEvents:UIControlEventTouchUpInside];
    [imgView addSubview:leftBtn];
    
    UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    rightBtn.frame = CGRectMake(SCREEN_WIDTH-88, 40, 78, 26);
    [rightBtn setBackgroundImage:[UIImage imageNamed:@"制作完成_05"] forState:UIControlStateNormal];
    [rightBtn addTarget:self action:@selector(clickRightBtn) forControlEvents:UIControlEventTouchUpInside];
    [imgView addSubview:rightBtn];
    
    UIImageView *dianImage = [[UIImageView alloc]initWithFrame:CGRectMake(20, leftBtn.bottom+53, 5, 5)];
    dianImage.image = [UIImage imageNamed:@"dian"];
    [imgView addSubview:dianImage];
    
    
    UILabel *zTitle = [[UILabel alloc]initWithFrame:CGRectMake(dianImage.right+5, leftBtn.bottom+40, SCREEN_WIDTH-40, 40)];
    zTitle.textColor = [UIColor whiteColor];
    zTitle.backgroundColor = [UIColor clearColor];
    zTitle.textAlignment = NSTextAlignmentLeft;
    if ([[[NSUserDefaults standardUserDefaults]objectForKey:@"zhonglei"] integerValue] == 0) {
        zTitle.text = @"展开面膜托盘，对准面膜机身的感应位置放好";
    }else{
        zTitle.text = @"请放入水";
    }
    zTitle.font = [UIFont systemFontOfSize:16];
    zTitle.numberOfLines = 0;
    [imgView addSubview:zTitle];
    
    if ([[[NSUserDefaults standardUserDefaults]objectForKey:@"zhonglei"] integerValue] == 0) {
        UIImageView *topImage = [[UIImageView alloc]initWithFrame:CGRectMake((SCREEN_WIDTH-282)/2, leftBtn.bottom+120, 282, 229)];
        topImage.image = [UIImage imageNamed:@"02放好托盘_03"];
        [imgView addSubview:topImage];
    }else{
        //UIImageView *topImage = [[UIImageView alloc]initWithFrame:CGRectMake((SCREEN_WIDTH-228)/2, leftBtn.bottom+100, 228, 235)];
        //topImage.image = [UIImage imageNamed:@"请放水_03"];
        //[imgView addSubview:topImage];
        Aimv = [OLImageView new];
        
        NSString *filePath = [[NSBundle mainBundle] pathForResource:@"04加水" ofType:@"gif"];
        NSData *GIFDATA = [NSData dataWithContentsOfFile:filePath];
        Aimv.image = [OLImage imageWithData:GIFDATA];
        Aimv.userInteractionEnabled = YES;
        [Aimv setFrame:CGRectMake((SCREEN_WIDTH-268)/2, leftBtn.bottom+100, 268, 261)];
        
        [self.view addSubview:Aimv];
    }
    
    UIButton *actionBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    actionBtn.frame = CGRectMake((SCREEN_WIDTH-93)/2, SCREEN_HEIGHT-94, 93, 84);
    [actionBtn setBackgroundImage:[UIImage imageNamed:@"制作完成_14"] forState:UIControlStateNormal];
    [actionBtn addTarget:self action:@selector(clickSure) forControlEvents:UIControlEventTouchUpInside];
    [imgView addSubview:actionBtn];
            
}
#pragma mark - 确定
-(void)clickSure{
    if ([[[NSUserDefaults standardUserDefaults]objectForKey:@"zhonglei"] integerValue] == 0) {
        AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
        appDelegate.isWhere = @"6";
        BeginMakingViewController *begin = [[BeginMakingViewController alloc]init];
        [self.navigationController pushViewController:begin animated:YES];
    }else{
        AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
        appDelegate.isWhere = @"6";
        TwoHuoXingtaiViewController *begin = [[TwoHuoXingtaiViewController alloc]init];
        [self.navigationController pushViewController:begin animated:YES];
    }
}
#pragma mark - 当运行到这步自动跳转
-(void)cdaoshui{
    AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
    appDelegate.isWhere = @"6";
    TwoHuoXingtaiViewController *begin = [[TwoHuoXingtaiViewController alloc]init];
    [self.navigationController pushViewController:begin animated:YES];
}
#pragma mark - 返回上一步
-(void)clickLeftBtn{
//    if ([[[NSUserDefaults standardUserDefaults]objectForKey:@"zhonglei"] integerValue] == 0) {
//        AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
//        appDelegate.isWhere = @"4";
//        [self.navigationController popViewControllerAnimated:YES];
//    }else{
//        AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
//        appDelegate.isWhere = @"4";
//        [self.navigationController popViewControllerAnimated:YES];
//    }
    ShopViewController *shop  = [[ShopViewController alloc]init];
    [self.navigationController pushViewController:shop animated:YES];
}

#pragma mark - 退出
-(void)clickRightBtn{
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:@"您确定退出么" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"取消", nil];
    [alert show];
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex == 0) {
        [[NSNotificationCenter defaultCenter]postNotificationName:@"cleanUp" object:nil];
        [self.navigationController popToRootViewControllerAnimated:YES];
    }
}
-(void)viewDidDisappear:(BOOL)animated{
    [Aimv removeFromSuperview];
    Aimv = nil;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
